package com.itheima.work01;

import java.util.concurrent.Semaphore;

public class Work5 extends Thread {
    private Semaphore semaphore = new Semaphore(2);

    @Override
    public void run() {
        try {
            semaphore.acquire();
            System.out.println("获取通行证");
            Thread.sleep(1000);
            System.out.println("归还通行证");
            semaphore.release();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
